<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="85%" destroy-on-close @closed="$emit('closed')" align-center>
        <el-header>
            <div class="right-panel-search">
                <div class="search-input">单号</div>
                <el-input v-model="search.keyword" placeholder="请输入单号" clearable />
                <div class="search-input">扣款类型</div>
                <el-select v-model="search.status" placeholder="类型" clearable>
                    <el-option v-for="item in deductionList" :key="item.id" :label="item.title" :value="item.id"/>
                </el-select>
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter border @selection-change="selectionChange" :params="query" height="550">
                <el-table-column type="selection" fixed width="50"></el-table-column>
                <el-table-column label="扣款单号" prop="order_no" align="center" width="150"></el-table-column>
                <el-table-column label="客户" prop="referred_as" align="center"></el-table-column>
                <el-table-column label="日期" prop="order_time" align="center"></el-table-column>
                <el-table-column label="类型" prop="type_name" align="center"></el-table-column>
                <el-table-column label="金额" prop="money" align="center"></el-table-column>
                <el-table-column label="备注" prop="remark" align="center"></el-table-column>
                <el-table-column label="状态" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.is_bill == 0" type="danger">未生成</el-tag>
                        <el-tag v-else type="success">已生成</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="图片" align="center" prop="other_images">
                    <template #default="scope">
                        <el-image class="img" :src="scope.row.other_images[0]" :preview-src-list="scope.row.other_images" :initial-index="0" fit="cover" preview-teleported="true" />
                    </template>
                </el-table-column>
                <el-table-column label="添加时间" align="center" prop="create_time"></el-table-column>
            </scTable>
        </el-main>
        <el-footer style="display:flex;justify-content: end;">
            <el-button @click="visible = false">取 消</el-button>
            <el-button type="primary" @click="submit()">确定</el-button>
        </el-footer>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
    props:{
        query: { type: String, default: "" },
    },
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择扣款单',
			},
			visible: false,
            apiObj: this.$API.inventory.cum.getDeduction.lists,
            dayArr:[],
            deducArr:[],
            search:{
                order_no:null,
                status: null,
            },
            customerList:[],
            deductionList:[],
		}
	},
    mounted() {
        this.getKeHu()
        this.getDeduc()
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        selectionChange(selection){
            selection.map(item=>{
                this.deducArr.push(item.id)
            })
        },
		//表单提交方法
        async submit() {
            var res = await this.$API.inventory.cum.createStatementBill.post({day_bill_ids:this.dayArr,deduction_bill_ids:this.deducArr});
            this.isSaveing = true;
            if (res.code == 1) {
                this.$emit('success', this.form, this.mode)
                this.visible = false;
                this.$message.success("操作成功")
            } else {
                this.$alert(res.message, "提示", { type: 'error' })
            }
		},
        setData(data){
            console.log('data :>> ', data);
            data.map(item=>{
                this.dayArr.push(item.id)
            })
        },
        // 获取客户
        async getKeHu(){
            var res = await this.$API.all.customer.get();
            this.customerList = res.data;
        },
        // 获取扣款原因
        async getDeduc(){
            var res = await this.$API.all.bill.get();
            this.deductionList = res.data;
        },
        //搜索
		upsearch() {
            console.log('this.search :>> ', this.search);
            this.$refs.table.upData(this.search)
		},
	}
}
</script>

<style>
.table .selected-row {
  background-color: #F00;
  /* 或者其他样式 */
}
</style>
